package cn.laixueit.controller;

import cn.laixueit.base.BaseController;
import cn.laixueit.base.R;
import cn.laixueit.pojo.Soft;
import cn.laixueit.service.SoftService;
import cn.laixueit.vo.SoftVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author duxiang
 * @date 2023/11/29 9:39
 */

@RestController
@RequestMapping("/soft")
@CrossOrigin
public class SoftController extends BaseController {
    @Resource
    private SoftService softService;

    @PostMapping("page/{page}/{size}")
    public R page(@PathVariable(name = "page")Integer page,
                  @PathVariable(name = "size")Integer size,
                  @RequestBody SoftVo softvo){
        Page<Soft> pageInfo = new Page<>(page, size);
        return softService.listPage(pageInfo,softvo);
    }

    @PostMapping("/save")
    public R save(@RequestBody Soft soft){
        softService.saveOrUpdateSoft(soft);
        return R.ok();
    }

    @PutMapping("/remove/{id}")
    public R remove(@PathVariable("id") String id){
        Soft soft = softService.getById(id);
        soft.setIsDelete(true);
        softService.updateById(soft);
        return R.ok();
    }

    @PutMapping("/recover/{id}")
    public R recover(@PathVariable("id") String id){
        Soft soft = softService.getById(id);
        soft.setIsDelete(false);
        softService.updateById(soft);
        return R.ok();
    }

    @GetMapping("/getRow/{id}")
    public R getRow(@PathVariable("id") String id){
        Soft soft = softService.getById(id);
        return R.ok().put("obj",soft);
    }

}
